import development from './development'
import production from './production'
import test from './test'

type Config = typeof development

const configs: Record<string, Config> = {
  development,
  production,
  test,
}

const env = process.env.NODE_ENV || 'development'
export const config = {
  ...configs[env],
  media: {
    rtmp: {
      port: 1935,
      chunk_size: 60000,
      gop_cache: true,
      ping: 30,
      ping_timeout: 60,
    },
    http: {
      port: 8000,
      allow_origin: '*',
      mediaroot: './media',
    },
    trans: {
      ffmpeg: process.platform === 'win32' ? 'C:\\ffmpeg\\bin\\ffmpeg.exe' : 'ffmpeg',
      tasks: [
        {
          app: 'live',
          hls: true,
          hlsFlags: '[hls_time=2:hls_list_size=3:hls_flags=delete_segments]',
          dash: false,
          dashFlags: '',
        },
      ],
    },
  },
  redis: {
    host: 'localhost',
    port: 6379,
    password: null,
    db: 0,
  },
  upload: {
    path: './uploads',
    maxSize: 5 * 1024 * 1024, // 5MB
    allowedTypes: ['jpg', 'jpeg', 'png', 'gif'],
  },
  rateLimit: {
    windowMs: 15 * 60 * 1000, // 15分钟
    max: 100, // 限制100次请求
  },
}

if (!config) {
  throw new Error(`Invalid environment: ${env}`)
}
